<div class="modal-header">
	<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
	<h4 class="modal-title"><font color="red">角色授权</font>&nbsp;</h4>
</div>
<div class="modal-body">
	<form class="form-horizontal" role="form" id="actForm">
	  <input name="userId" id="act-userId" type="hidden">
	<!-- Custom Tabs -->
		<div class="nav-tabs-custom">
	    <div class="tab-content">
			<div class="tab-pane active" id="tab_1">
				<table id="role-actsTable" class="table table-bordered table-hover" >
					<thead>
					<tr><th>资源名</th>
						<th>资源英文全称</th><th>操作</th>
					</tr>
					</thead>
					<tbody id="roleActsList"></tbody>
				</table>
			</div>
		</div>
	</div>
    </form>
</div>
<script type="text/template" id="roleListData">
	  		<? for ( var i = 0; i < rows.length; i++) {?>
				<tr id="role_<?=rows[i].actId?>"  roleFatherId=<?=rows[i].fatherId?>>
					<th style="display:none;"><?=rows[i].actId?></th>
					<th style="display:none;"><?=rows[i].actCname?></th>
					<th style="display:none;"><?=rows[i].fatherId?></th>
					<td><?if(rows[i].subCount>0){?>
							<i class="fa fa-folder" onclick="getChildRoleActsData('<?=rows[i].actId?>','<?=rows[i].fullEname?>',this);">&nbsp;<?=rows[i].actCname?></i>
						<?} else{?>		
							<i class="fa fa-file"></i>&nbsp;<?=rows[i].actCname?>
						<?}?></td>
					<td><?=rows[i].fullEname?></td>
					<td><?if("T"==rows[i].hasGive){?>
                        <i class="fa fa-check fa-2x" ondblclick="giveRole(this,'<?=rows[i].actId?>');"></i>
                       <?}else{?>
                       <i class="fa fa-close fa-2x" ondblclick="giveRole(this,'<?=rows[i].actId?>');"></i>
                       <?}?></td>
				</tr>
     		<?}?>
	</script>
	
<script>
var _roleId;
function getRoleListData(roleId,fatherId){
_roleId=roleId;
	//deleteAllRow('roleActsList');
	$("#act-userId").val(id);
	$.ajax({ type:'post', url:ctx+'/res/uct/admin/roleActData?roleId='+roleId+"&id="+fatherId,
		   data:$('#actFrom').serialize(), dataType:'json',
		   success: function(myData){
		    var myDatas = new Object();
		    myDatas.rows = myData;
			var data = baidu.template('roleListData',eval(myDatas));  
			$("#roleActsList").html(data);
		   }
	 });	
  } 
function giveRole(obj,actId){
   var flag = "add";
   if($(obj).hasClass('fa-check')){
	   flag = "del";
   }
   $.ajax({type: "post",
		url: ctx+"/res/uct/admin/authorizeAct?actGiveType=role&flag="+flag+"&id="+actId+"&objId="+_roleId,
		success: function(data, textStatus){
			if($(obj).hasClass('fa-check')){
				$(obj).attr("class","fa fa-close fa-2x");
			}else{
				$(obj).attr("class","fa fa-check fa-2x");
			}
		}
   });
}

function getChildRoleActsData(actId,treeLevel,obj){
var count =0;
var ss = treeLevel.split("/");
count = ss.length-1;
	$.ajax({
		   type:'post',
		   url:ctx+'/res/uct/admin/roleActData',
		   data:{'id':actId,'roleId':_roleId},
		   dataType:'json',
		   success: function(myData){
		    var myDatas = new Object();
		    myDatas.rows = myData;
			var data = baidu.template('roleListData',myDatas); 
			if($(obj).hasClass("fa-folder-open")){
				$(obj).attr("class","fa fa-folder");
				delRoleActsChiled(actId);
			}else{
				$(obj).attr("class","fa fa-folder-open");
				$("#role_"+actId).after(data);
				 $("[roleFatherId='"+actId+"']").each(function(i){
					var thisObj = $(this);
					var pd = "10px 20px 10px ";
					var num = pd+(count*20)+"px";
					$(thisObj).find("td").eq(0).css("padding",num);
				 });
			 }
		   }
		});	
  } 
  function delRoleActsChiled(id){
	  $("[roleFatherId='"+id+"']").each(function(i){
			 var thisObj = $(this);
			 $(thisObj).remove();
			 var id = thisObj.attr("id");
			 delRoleActsChiled(id);
		 });
  }
</script>